package org.msss.gamebasic;

import org.lwjgl.opengl.GL11;
import org.newdawn.slick.Color;
import org.newdawn.slick.opengl.Texture;

public class Canvas {

	/**
	 * Draw a rectangle according to the room.
	 * 
	 * @param c
	 *            Color
	 * @param x
	 *            X
	 * @param y
	 *            Y
	 * @param width
	 *            Width
	 * @param height
	 *            Height
	 * @param depth
	 *            Depth
	 */
	public static void drawRectangleToRoom(Color c, int x, int y, int width,
			int height, int depth) {
		int offx = Game.view.getX();
		int offy = Game.view.getY();

		GL11.glBegin(GL11.GL_QUADS);

		GL11.glColor4f((float) c.getRed() / 255f, (float) c.getGreen() / 255f,
				(float) c.getBlue() / 255f, (float) c.getAlpha() / 255f);

		GL11.glVertex3d(x - offx, y - offy, depth);
		GL11.glVertex3d(x - offx, y + height - offy, depth);
		GL11.glVertex3d(x + width - offx, y + height - offy, depth);
		GL11.glVertex3d(x + width - offx, y - offy, depth);

		GL11.glEnd();
	}

	/**
	 * Draw a rectangle according to the view.
	 * 
	 * @param c
	 *            Color
	 * @param x
	 *            X
	 * @param y
	 *            Y
	 * @param width
	 *            Width
	 * @param height
	 *            Height
	 * @param depth
	 *            Depth
	 */
	public static void drawRectangleToView(Color c, int x, int y, int width,
			int height, int depth) {

		GL11.glBegin(GL11.GL_QUADS);

		GL11.glColor4f((float) c.getRed() / 255f, (float) c.getGreen() / 255f,
				(float) c.getBlue() / 255f, (float) c.getAlpha() / 255f);

		GL11.glVertex3d(x, y, depth);
		GL11.glVertex3d(x, y + height, depth);
		GL11.glVertex3d(x + width, y + height, depth);
		GL11.glVertex3d(x + width, y, depth);

		GL11.glEnd();
	}

	public static void drawImageToRoom(Texture t, int x, int y, int width,
			int height, int depth) {
		int offx = Game.view.getX();
		int offy = Game.view.getY();

		GL11.glBegin(GL11.GL_QUADS);

		Color.white.bind();
		t.bind();

		GL11.glTexCoord2f(0, 0);
		GL11.glVertex3d(x - offx, y - offy, depth);
		GL11.glTexCoord2f(0, 1);
		GL11.glVertex3d(x - offx, y + height - offy, depth);
		GL11.glTexCoord2f(1, 1);
		GL11.glVertex3d(x + width - offx, y + height - offy, depth);
		GL11.glTexCoord2f(1, 0);
		GL11.glVertex3d(x + width - offx, y - offy, depth);

		GL11.glEnd();
	}

	public static void drawImageToView(Texture t, int x, int y, int width,
			int height, int depth) {

		GL11.glBegin(GL11.GL_QUADS);

		Color.white.bind();
		t.bind();

		GL11.glTexCoord2f(0, 0);
		GL11.glVertex3d(x, y, depth);
		GL11.glTexCoord2f(0, 1);
		GL11.glVertex3d(x, y + height, depth);
		GL11.glTexCoord2f(1, 1);
		GL11.glVertex3d(x + width, y + height, depth);
		GL11.glTexCoord2f(1, 0);
		GL11.glVertex3d(x + width, y, depth);

		GL11.glEnd();
	}
}
